﻿using BaseUI;
using BLL;
using System;
using System.Data;
using System.Linq;
using System.Web.UI.WebControls;
using Thksoft.Module.DataDetail;

namespace Thksoft.UserCotrols
{
    public partial class PlanDetailSix_Year : BaseControl
    {
        public DataTable dt;
        public int proType { get; set; }

        protected void Page_Load(object sender, EventArgs e)
        {
            //BindData();
        }

        //城市管网项目周明细表(T6)
        public void BindData()
        {
            var pPage = this.Page as ProjectFundDetail_Year;

            lblyear.Text = pPage.myDate;
            lbldw.Text = pPage.cmyName;
            lblTime.Text = pPage.valTime;
            HiddenField1.Value = pPage.year;

            switch (proType)
            {
                case 1: lblProjectName.Text = "安装外包费用年明细表"; break;
                case 2: lblProjectName.Text = "材料费用年明细表"; break;
                case 3: lblProjectName.Text = "大修费用年明细表"; break;
                default: lblProjectName.Text = "城市管网项目年明细表"; break;
            }
            dt = new QS_PLAN_DETAIL3_BLL().GetTable(pPage.planappId, 1, proType);

            var row = dt.NewRow();
            row["N_GZAMOUNT"] = dt.AsEnumerable().Sum(a => a["N_GZAMOUNT"] == DBNull.Value ? 0 : Convert.ToDecimal(a["N_GZAMOUNT"]));
            row["N_PLANAMOUNT"] = dt.AsEnumerable().Sum(a => a["N_PLANAMOUNT"] == DBNull.Value ? 0 : Convert.ToDecimal(a["N_PLANAMOUNT"]));
            row["N_REAMOUNT"] = dt.AsEnumerable().Sum(a => a["N_REAMOUNT"] == DBNull.Value ? 0 : Convert.ToDecimal(a["N_REAMOUNT"]));
            row["C_PRONAME"] = "合计";
            dt.Rows.Add(row);

            ViewState["database"] = dt;
            grvShow6.DataSource = dt;
            grvShow6.DataBind();
        }

        /// <summary>
        /// 排序
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void grvShow1_Sorting(object sender, GridViewSortEventArgs e)
        {
            string sPage = e.SortExpression;
            string SortOrder, OrderDire;
            SortOrder = ViewState["ORDER"] == null ? null : (string)ViewState["ORDER"];
            OrderDire = ViewState["ORDER_TYPE"] == null ? null : (string)ViewState["ORDER_TYPE"];
            if (SortOrder == sPage)
            {
                if (OrderDire == "DESC")
                    OrderDire = "ASC";
                else
                    OrderDire = "DESC";
            }
            else
            {
                SortOrder = e.SortExpression;
                OrderDire = "ASC";
            }
            ViewState["ORDER"] = SortOrder;
            ViewState["ORDER_TYPE"] = OrderDire;
        }

        public void BindDaodu()
        {
            var execll = new BasePage();
            execll.toExecl1(Panel1, lblProjectName.Text + DateTime.Now.ToString("yyyyMMdd") + DateTime.Now.Millisecond.ToString());
        }

        public void BindPrint()
        {
            var key = Guid.NewGuid().ToString();
            Session[key] = FORM_PRINT_VALUE.Value;
            MessageBox.ResponseScript(Page, "top.MessageBox.Print({Value:\"ID=HTML&VALUE=" + key + "\",Area:[\"800px\",\"500px\"],Scrollbar:true})");
        }
    }
}